/*
 * @Author: Huangdong
 * @Date: 2022-03-28 15:21:05
 * @LastEditors: minsheng_insurance_agency_zhoucl
 * @LastEditTime: 2025-07-22 14:07:11
 * @FilePath: \02.bldinsure\src\store\index.js
 * @Description:
 *
 *
 */
import Vue from "vue";
import Vuex from "vuex";
import createPersistedState from "vuex-persistedstate";

import modules from "./modules/index";

Vue.use(Vuex);

// let clearTime;
let showTimes = 0;
const config = {
  modules,
  plugins: [
    createPersistedState({
      storage: window.sessionStorage,
      key: "bld_insure",
    }),
  ],
  state: {
    /**接口加载*/
    vLoad: false,
    loadTxt: "数据加载中",
    /**新进，清缓存*/
    vstamp: "",
  },
  getters: {
    vLoad: (state) => state.vLoad,
    loadTxt: (state) => state.loadTxt,
    vstamp: (state) => state.vstamp,
  },
  mutations: {
    UPDATE_MAIN_STATE(state, payload) {
      Object.assign(state, payload);
    },
    updateLoad(state, payload) {
      // clearTime && clearTimeout(clearTime);
      if (payload) {
        showTimes++;
        if (showTimes == 1) return; // 避免异常未关闭 30s自动关闭
      } else {
        state.loadTxt = "数据加载中";
      }
      state.vLoad = payload;
    },
    updateLoadTxt(state, payload) {
      state.loadTxt = payload;
    },
    SET_STAMP(state, payload) {
      state.vstamp = payload;
    },
  },
  actions: {},
};
const store = new Vuex.Store(config);
export default store;
